package com.example.boot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.AopLogs;
import com.example.common.LogAnno;
import com.example.common.Result;
import com.example.common.enums.LogType;
import com.example.pojo.entity.Admin;
import com.example.pojo.entity.Device;
import com.example.pojo.entity.User;
import com.example.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * TODO
 *
 * @author wy
 * @since 2024/7/16
 */
@RestController
@RequestMapping("/user")
@Api(tags = "员工接口")
public class UserController {

    @Resource
    private IUserService iUserService;

    /**
     * 新增
     */
    @ApiOperation("新增员工信息")
    @PostMapping("/add")
    public Result add(@ApiParam("员工信息") @RequestBody User user) {
        iUserService.add(user);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation("根据ID删除员工信息")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@ApiParam("员工ID") @PathVariable Integer id) {
        iUserService.deleteById(id);
        return Result.success();
    }

    /**
     * 修改
     */
    @ApiOperation("更新员工信息")
    @PutMapping("/update")
    public Result updateById(@RequestBody User user) {
        iUserService.updateById(user);
        return Result.success();
    }
    /**
     * 分页查询
     */
    @ApiOperation("员工信息列表分页查询")
    @GetMapping("/selectPage")
    public Result selectPage(User user,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<User> page = iUserService.selectPage(user, pageNum, pageSize);
        return Result.success(page);
    }
}
